/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Util;

import Database.*;

import java.sql.*;
import java.util.Vector;

/**
 *
 * @author Jack
 */
public class BugReport {

    private int idreport;
    private int idcustomer;
    private int idfrontend;
    private int iddispatch;
    private int idtype;
    private String title;
    private String content;
    private java.sql.Date datereceive;
    private java.sql.Date datefinish;
    private int idstatus;

    /**
     * @return the idcustomer
     */
    public int getIdcustomer() {
        return idcustomer;
    }

    /**
     * @param idcustomer the idcustomer to set
     */
    public void setIdcustomer(int idcustomer) {
        this.idcustomer = idcustomer;
    }

    /**
     * @return the idfrontend
     */
    public int getIdfrontend() {
        return idfrontend;
    }

    /**
     * @param idfrontend the idfrontend to set
     */
    public void setIdfrontend(int idfrontend) {
        this.idfrontend = idfrontend;
    }

    /**
     * @return the iddispatch
     */
    public int getIddispatch() {
        return iddispatch;
    }

    /**
     * @param iddispatch the iddispatch to set
     */
    public void setIddispatch(int iddispatch) {
        this.iddispatch = iddispatch;
    }

    /**
     * @return the idtype
     */
    public int getIdtype() {
        return idtype;
    }

    /**
     * @param idtype the idtype to set
     */
    public void setIdtype(int idtype) {
        this.idtype = idtype;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * @return the content
     */
    public String getContent() {
        return content;
    }

    /**
     * @param content the content to set
     */
    public void setContent(String content) {
        this.content = content;
    }

    /**
     * @return the datereceive
     */
    public java.sql.Date getDatereceive() {
        return datereceive;
    }

    /**
     * @param datereceive the datereceive to set
     */
    public void setDatereceive(java.sql.Date datereceive) {
        this.datereceive = datereceive;
    }

    /**
     * @return the datefinish
     */
    public java.sql.Date getDatefinish() {
        return datefinish;
    }

    /**
     * @param datefinish the datefinish to set
     */
    public void setDatefinish(java.sql.Date datefinish) {
        this.datefinish = datefinish;
    }

    /**
     * @return the status
     */
    public int getIDStatus() {
        return idstatus;
    }

    /**
     * @param status the status to set
     */
    public void setIDStatus(int status) {
        this.idstatus = status;
    }

    /**
     * @return the datesolve
     */
    /**
     * @return the idreport
     */
    public int getIdreport() {
        return idreport;
    }

    /**
     * @param idreport the idreport to set
     */
    public void setIdreport(int idreport) {
        this.idreport = idreport;
    }

    public boolean AddReportFontEnd() {
        return CommonQuery.Command("insert into BugReport values(" + this.idcustomer + "," + this.iddispatch + "," + this.idfrontend + "," + this.idtype + ",'" + this.title + "','" + this.content + "','" + this.datereceive + "','" + this.datefinish + "'," + this.idstatus + ")");
    }

    public static Vector<BugReport> ListIDRP() {
        Vector<BugReport> liste = new Vector<BugReport>();
        try {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select * from bugreport" + " order by idreport desc";
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                BugReport br = new BugReport();
                br.setIdreport(rs.getInt("idreport"));
                br.setIdcustomer(rs.getInt("idcustomer"));
                br.setIddispatch(rs.getInt("iddispatch"));
                br.setIdfrontend(rs.getInt("idfrontend"));
                br.setIdtype(rs.getInt("idtype"));
                br.setTitle(rs.getString("title"));
                br.setContent(rs.getString("contentreport"));
                br.setDatereceive(rs.getDate("date_receive"));
                br.setDatefinish(rs.getDate("date_finish"));
                br.setIDStatus(rs.getInt("idstatus"));

                liste.add(br);
            }
        } catch (Exception ex) {
            liste = null;
        }
        return liste;
    }

    public static Vector<BugReport> ListIDRPONSTATUS(int ipstatus) {
        Vector<BugReport> liste = new Vector<BugReport>();
        try {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select * from bugreport where idstatus=" + ipstatus + " order by idreport desc";
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                BugReport br = new BugReport();
                br.setIdreport(rs.getInt("idreport"));
                br.setIdcustomer(rs.getInt("idcustomer"));
                br.setIddispatch(rs.getInt("iddispatch"));
                br.setIdfrontend(rs.getInt("idfrontend"));
                br.setIdtype(rs.getInt("idtype"));
                br.setTitle(rs.getString("title"));
                br.setContent(rs.getString("contentreport"));
                br.setDatereceive(rs.getDate("date_receive"));
                br.setDatefinish(rs.getDate("date_finish"));
                br.setIDStatus(rs.getInt("idstatus"));

                liste.add(br);
            }
        } catch (Exception ex) {
            liste = null;
        }
        return liste;
    }

    public static Vector<BugReport> ListIDRPONIPDISPATCH(int iddispatch) {
        Vector<BugReport> liste = new Vector<BugReport>();
        try {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select * from bugreport where iddispatch=" + iddispatch + " order by idreport desc";
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                BugReport br = new BugReport();
                br.setIdreport(rs.getInt("idreport"));
                br.setIdcustomer(rs.getInt("idcustomer"));
                br.setIddispatch(rs.getInt("iddispatch"));
                br.setIdfrontend(rs.getInt("idfrontend"));
                br.setIdtype(rs.getInt("idtype"));
                br.setTitle(rs.getString("title"));
                br.setContent(rs.getString("contentreport"));
                br.setDatereceive(rs.getDate("date_receive"));
                br.setDatefinish(rs.getDate("date_finish"));
                br.setIDStatus(rs.getInt("idstatus"));

                liste.add(br);
            }
        } catch (Exception ex) {
            liste = null;
        }
        return liste;
    }

    public static Vector<BugReport> ListIDRPONIPDISPATCHANDTYPE(int iddispatch, int type) {
        Vector<BugReport> liste = new Vector<BugReport>();
        try {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select * from bugreport where iddispatch=" + iddispatch + "and idtype=" + type + " order by idreport desc";
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                BugReport br = new BugReport();
                br.setIdreport(rs.getInt("idreport"));
                br.setIdcustomer(rs.getInt("idcustomer"));
                br.setIddispatch(rs.getInt("iddispatch"));
                br.setIdfrontend(rs.getInt("idfrontend"));
                br.setIdtype(rs.getInt("idtype"));
                br.setTitle(rs.getString("title"));
                br.setContent(rs.getString("contentreport"));
                br.setDatereceive(rs.getDate("date_receive"));
                br.setDatefinish(rs.getDate("date_finish"));
                br.setIDStatus(rs.getInt("idstatus"));

                liste.add(br);
            }
        } catch (Exception ex) {
            liste = null;
        }
        return liste;
    }

    public static Vector<BugReport> ListReportonType_Status(int ipstatus, int type) {
        Vector<BugReport> liste = new Vector<BugReport>();
        try {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select * from bugreport where idstatus=" + ipstatus + "and idtype=" + type + " order by idreport desc";
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                BugReport br = new BugReport();
                br.setIdreport(rs.getInt("idreport"));
                br.setIdcustomer(rs.getInt("idcustomer"));
                br.setIddispatch(rs.getInt("iddispatch"));
                br.setIdfrontend(rs.getInt("idfrontend"));
                br.setIdtype(rs.getInt("idtype"));
                br.setTitle(rs.getString("title"));
                br.setContent(rs.getString("contentreport"));
                br.setDatereceive(rs.getDate("date_receive"));
                br.setDatefinish(rs.getDate("date_finish"));
                br.setIDStatus(rs.getInt("idstatus"));

                liste.add(br);
            }
        } catch (Exception ex) {
            liste = null;
        }
        return liste;
    }

    public static Vector<BugReport> ListReportonType(int type) {
        Vector<BugReport> liste = new Vector<BugReport>();
        try {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select * from bugreport where idtype=" + type + " order by idreport desc";
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                BugReport br = new BugReport();
                br.setIdreport(rs.getInt("idreport"));
                br.setIdcustomer(rs.getInt("idcustomer"));
                br.setIddispatch(rs.getInt("iddispatch"));
                br.setIdfrontend(rs.getInt("idfrontend"));
                br.setIdtype(rs.getInt("idtype"));
                br.setTitle(rs.getString("title"));
                br.setContent(rs.getString("contentreport"));
                br.setDatereceive(rs.getDate("date_receive"));
                br.setDatefinish(rs.getDate("date_finish"));
                br.setIDStatus(rs.getInt("idstatus"));

                liste.add(br);
            }
        } catch (Exception ex) {
            liste = null;
        }
        return liste;
    }

    public static Vector<BugReport> ListReportonTypeAndDateAndStatus(int ipstatus, java.sql.Date datefinish, int type) {
        Vector<BugReport> liste = new Vector<BugReport>();
        try {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select * from bugreport where idstatus=" + ipstatus + "and date_finish='" + datefinish + "' and idtype=" + type + " order by idreport desc";
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                BugReport br = new BugReport();
                br.setIdreport(rs.getInt("idreport"));
                br.setIdcustomer(rs.getInt("idcustomer"));
                br.setIddispatch(rs.getInt("iddispatch"));
                br.setIdfrontend(rs.getInt("idfrontend"));
                br.setIdtype(rs.getInt("idtype"));
                br.setTitle(rs.getString("title"));
                br.setContent(rs.getString("contentreport"));
                br.setDatereceive(rs.getDate("date_receive"));
                br.setDatefinish(rs.getDate("date_finish"));
                br.setIDStatus(rs.getInt("idstatus"));

                liste.add(br);
            }
        } catch (Exception ex) {
            liste = null;
        }
        return liste;
    }

    public static Vector<BugReport> ListReportonTypeAndDate(java.sql.Date datefinish, int type) {
        Vector<BugReport> liste = new Vector<BugReport>();
        try {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select * from bugreport where date_finish='" + datefinish + "' and idtype=" + type + " order by idreport desc";
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                BugReport br = new BugReport();
                br.setIdreport(rs.getInt("idreport"));
                br.setIdcustomer(rs.getInt("idcustomer"));
                br.setIddispatch(rs.getInt("iddispatch"));
                br.setIdfrontend(rs.getInt("idfrontend"));
                br.setIdtype(rs.getInt("idtype"));
                br.setTitle(rs.getString("title"));
                br.setContent(rs.getString("contentreport"));
                br.setDatereceive(rs.getDate("date_receive"));
                br.setDatefinish(rs.getDate("date_finish"));
                br.setIDStatus(rs.getInt("idstatus"));

                liste.add(br);
            }
        } catch (Exception ex) {
            liste = null;
        }
        return liste;
    }

    public static Vector<BugReport> ListReportOnDate(java.sql.Date datefinish) {
        Vector<BugReport> liste = new Vector<BugReport>();
        try {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select * from bugreport where date_finish='" + datefinish + "'" + " order by idreport desc";
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                BugReport br = new BugReport();
                br.setIdreport(rs.getInt("idreport"));
                br.setIdcustomer(rs.getInt("idcustomer"));
                br.setIddispatch(rs.getInt("iddispatch"));
                br.setIdfrontend(rs.getInt("idfrontend"));
                br.setIdtype(rs.getInt("idtype"));
                br.setTitle(rs.getString("title"));
                br.setContent(rs.getString("contentreport"));
                br.setDatereceive(rs.getDate("date_receive"));
                br.setDatefinish(rs.getDate("date_finish"));
                br.setIDStatus(rs.getInt("idstatus"));

                liste.add(br);
            }
        } catch (Exception ex) {
            liste = null;
        }
        return liste;
    }

    public static Vector<BugReport> ListReportOnDateandStatus(java.sql.Date datefinish, int status) {
        Vector<BugReport> liste = new Vector<BugReport>();
        try {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select * from bugreport where date_finish='" + datefinish + "' and idstatus=" + status + " order by idreport desc";
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                BugReport br = new BugReport();
                br.setIdreport(rs.getInt("idreport"));
                br.setIdcustomer(rs.getInt("idcustomer"));
                br.setIddispatch(rs.getInt("iddispatch"));
                br.setIdfrontend(rs.getInt("idfrontend"));
                br.setIdtype(rs.getInt("idtype"));
                br.setTitle(rs.getString("title"));
                br.setContent(rs.getString("contentreport"));
                br.setDatereceive(rs.getDate("date_receive"));
                br.setDatefinish(rs.getDate("date_finish"));
                br.setIDStatus(rs.getInt("idstatus"));

                liste.add(br);
            }
        } catch (Exception ex) {
            liste = null;
        }
        return liste;
    }

    public static String ListNameFontEnd(int a) {
        String liste = "";
        try {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select nameemployee from employee,bugreport where bugreport.idfrontend=employee.idemployee and bugreport.idreport=" + a;
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                liste = rs.getString("nameemployee");
            }
        } catch (Exception ex) {
            liste = null;
        }
        return liste;
    }

    public static Vector<BugReport> ListReportONIDReport(int idreport) {
        Vector<BugReport> liste = new Vector<BugReport>();
        try {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select * from bugreport where idreport=" + idreport + " order by idreport desc";
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                BugReport br = new BugReport();
                br.setIdreport(rs.getInt("idreport"));
                br.setIdcustomer(rs.getInt("idcustomer"));
                br.setIddispatch(rs.getInt("iddispatch"));
                br.setIdfrontend(rs.getInt("idfrontend"));
                br.setIdtype(rs.getInt("idtype"));
                br.setTitle(rs.getString("title"));
                br.setContent(rs.getString("contentreport"));
                br.setDatereceive(rs.getDate("date_receive"));
                br.setDatefinish(rs.getDate("date_finish"));
                br.setIDStatus(rs.getInt("idstatus"));

                liste.add(br);
            }
        } catch (Exception ex) {
            liste = null;
        }
        return liste;
    }

    public boolean updatestatus() {
        return CommonQuery.Command("update bugreport set idstatus=" + this.idstatus + " where idreport=" + this.idreport);
    }

    public boolean updatebugreport() {
        return CommonQuery.Command("update bugreport set idcustomer=" + this.idcustomer + ",iddispatch=" + this.iddispatch + ",idfrontend=" + this.idfrontend + ",idtype=" + this.idtype + ",title='" + this.title + "',contentreport='" + this.content + "',date_receive='" + this.datereceive + "',date_finish='" + this.datefinish + "' where idreport=" + this.idreport);
    }
}
